﻿function selChanged( selboxID, limit  ) {
	var selbox = document.getElementById( selboxID );
	if( selbox.length > limit )
		selbox.remove( 0 );
}// end function SelChanged

function submitForm( formID ) {
	var form = document.getElementById( formID );
	form.submit();
}// end function submitForm

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	return { top: scrOfY, left: scrOfX };
}

function switchPage( element, task, page ) {
	
	page--;
	var  xOffset = getScrollXY().left;
	var yOffset = getScrollXY().top;
	var newURL = '.?' + task + '&index=' + page + '&scrollx=' + xOffset +'&scrolly=' + yOffset;
	element.href = newURL;
}// end function switchPage

function switchTab( page ) {
	// switching navigation tabs
	var navtab = document.getElementById( 'navtab' );
	var tabs = navtab.getElementsByTagName( 'a' );
	for( var x = 0; x < tabs.length; x++ ) {
		if( x == page )
			tabs[x].className = 'selected';
		else
			tabs[x].className = '';
	}
	//switching tables
	var tables = document.getElementsByTagName( 'table' );
	var style;
	for( var i = 0; i < tables.length; i++ ) {
		if( i == page - 1 || page == 0)
			style = '';
		else
			style = 'none';
		tables[i].parentNode.parentNode.style.display = style;
		//if( spaces[i].className == 'space' )
		//	spaces[i].style.display = style;
	}
	
	// switch div spaces
	if( page == 0 ) {
		// get div space
		var dw = document.getElementById( 'data-wrapper' );
		var spaces = document.getElementsByTagName( 'div' );
		for( var j = 1; j < spaces.length; i++ ) {
			if( spaces[i].className == 'space' )
				spaces[i].style.display = '';
		}
	}
	else {
		// get div space
		var dw = document.getElementById( 'data-wrapper' );
		var spaces = document.getElementsByTagName( 'div' );
		for( var j = 1; j < spaces.length; i++ ) {
			if( spaces[i].className == 'space' )
				spaces[i].style.display = 'none';
		}
	}
}// end function switchTab

function savPos( form ) {

	var xScroll = getScrollXY().left;
	var yScroll = getScrollXY().top;
	
	//Create an input type dynamically.
	var eleX = document.createElement("input");

	//Assign different attributes to the element.
	eleX.setAttribute("type", "hidden");
	eleX.setAttribute("value", xScroll);
	eleX.setAttribute("name", "scrollx");
	
	var eleY = document.createElement( "input" );
	
	eleY.setAttribute( "type", "hidden" );
	eleY.setAttribute( "value", yScroll );
	eleY.setAttribute( "name", "scrolly" );
	
	

	//Append the element in page (in span).
	form.appendChild(eleX);
	form.appendChild(eleY);
	
}// end function savPos